package com.study.activemq.consumer;

import org.springframework.jms.annotation.JmsListener;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Component;

@Component
public class Consumer {

	/**
	 * 接收 test.queue 队列的消息
	 * @param text
	 */
	@JmsListener(destination = "test.queue")
    public void receiveQueue(String text) {
        System.out.println("Consumer收到的报文为:"+text);
    }
	
	/**
	 * 接收队列消息
	 * @param text
	 * @return
	 */
	@JmsListener(destination = "publish.queue", containerFactory = "jmsListenerContainerQueue")
    @SendTo("out.queue") // 当 out.queue 不存在时，会自动创建该队列
    public String receivequeue(String text){
        System.out.println("QueueListener: consumer-a 收到一条信息: " + text);
        return "consumer-a received : " + text;
    }
	
	/**
	 * 接收topic消息
	 * @param text
	 */
	@JmsListener(destination = "publish.topic", containerFactory = "jmsListenerContainerTopic")
	@SendTo("out.topic") // 当 out.topic 不存在时，会自动创建该主题
    public String receivetopic(String text){
        System.out.println("TopicListener: consumer-a 收到一条信息: " + text);
        return "TopicListener ,topic反馈";
    }
}
